function UgovoriZakjNapRepRadDetails(radid,tr){
	var tbl = document.getElementById("radnik_details");
	if(tbl){
		
		var trsrc = tr.parentNode.getElementsByTagName("tr");
		for(var i=0; i<trsrc.length; i++){
			trsrc[i].className = trsrc[i].className.replace("CurrentRadnikRow","");
		}
		tr.className = "CurrentRadnikRow";
		
		var tr = tbl.getElementsByTagName("tr");
		tr[0].style.display = "table-row";
		tr[1].style.display = "table-row";
		
		for(var i=2; i<tr.length; i++){
			if(tr[i].getAttribute("radnik")==radid){
				tr[i].style.display = "table-row";
			}else{
				tr[i].style.display = "none";
			}
		}
	}
}
function CopyFilteredUgovors(table){
	exportCSV(table);
	/*var tr = table.getElementsByTagName("tr");
	var cpdata = "<table>";
	var ima=false;
	for(var i=0; i<tr.length; i++){
		if(tr[i].style.display != "none"){
			ima=true;
			cpdata += "<tr>"+trim(tr[i].innerHTML)+"</tr>";
		}
	}
	cpdata += "</table>";
	if(ima){
		CopyToClipboard(cpdata);
		alert("Copied");
	}*/
}

function onComboRadniciBlur(e)
{
	var combo=e.target;
	var parent=combo.parentNode;
	parent.removeChild(combo);
	if (combo.selectedIndex>0 && parent.tagName=="TD")
		parent.innerHTML=combo.options[combo.selectedIndex].innerHTML;
	combo.style.display="none";
	document.getElementById("divRadnici").appendChild(combo);
}

function onCellPozivalacClick(e) {
	var combo=document.getElementById("radnici");
	var parent=combo.parentNode;
	parent.removeChild(combo);
	var td=e.target;
	var radnik=td.innerHTML;
	td.innerHTML="";
	td.appendChild(combo);
	combo.selectedIndex=0;
	for (var i=1;i<combo.options.length;i++)
		if(combo.options[i].innerHTML==radnik)
		{	
			combo.selectedIndex=i;
			break;
		}
	combo.style.display="block";
	combo.focus();
	e.stopPropagation();
}

function onComboRadniciChange(e)
{
	var combo=e.target;
	var td=combo.parentNode;
	var ugovor=td.getAttribute("ugovor");
	var user_id="";
	if (combo.selectedIndex>0)
	{
		user_id=combo.options[combo.selectedIndex].value;
		td.setAttribute("pozivalac_user_id",user_id);
	}
	else td.attributes.removeNamedItem("pozivalac_user_id");
	LoadRSDoc("ugovori.php?a=real_report&a2=pozivaoci&user="+user_id+"&ugo="+ugovor,"afterTaskListSaved");	
	e.stopPropagation();
}

function refreshComboFilterPozivaoci()
{
	var combo_filter=document.getElementById("filter_pozivalac");
	while (combo_filter.options.length>1)
		combo_filter.remove(1);
	var tbl=document.getElementById("ResultTable");
	for (var row=2;row<tbl.rows.length;row++)
		for (var col=0;col<tbl.rows[row].cells.length;col++)
		{
			var td=tbl.rows[row].cells[col];
			var user_id=td.getAttribute("pozivalac_user_id");
			if (user_id)
			{
				var found=0;
				for (var i=0;i<combo_filter.options.length;i++)
					if (combo_filter.options[i].value==user_id)
					{
						found=1;
						break;
					}
				if (found) break;
				var option=document.createElement("option");
				option.setAttribute("value",user_id);
				option.innerHTML=td.innerHTML;
				combo_filter.add(option,null);
				break;
			}
		}
}

function afterTaskListSaved(result) {
	var combo=document.getElementById("radnici");
	combo.blur();
	refreshComboFilterPozivaoci();
	alert(result)
}
